package com.wei.controller;

import com.wei.entity.Video;
import com.wei.service.VideoService;
import com.wei.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author wjx
 * @ClassName VideoController
 * @description: TODO
 * @date 2022-11-29 21:14
 * @version: 1.0
 */
@RestController
@RequestMapping("/eduservice/video")
public class VideoController {


    @Autowired
    private VideoService videoService;

    @PostMapping("/addVideo")
    public R addVideo(@RequestBody Video video) {

        boolean save = videoService.save(video);

        return save ? R.ok() : R.error();
    }

    @GetMapping("/getVideoById/{id}")
    public R getVideoById(@PathVariable String id) {
        Video video = videoService.getById(id);

        return R.ok().data("video", video);
    }

    @PostMapping("/updateVideo")
    public R updateVideo(@RequestBody Video video) {
        boolean update = videoService.updateById(video);

        return update ? R.ok() : R.error();
    }

    /**
     * 删除小节
     *
     * @param id
     * @return
     */
    @DeleteMapping("/deleteVideoById/{id}")
    public R deleteVideoById(@PathVariable String id) {
        videoService.deleteVideoById(id);
        return R.ok();
    }
}
